package com.javier.nfcpass;

import android.content.BroadcastReceiver;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.nfc.NfcAdapter;
import android.util.Log;
import android.widget.TextView;


public class MyBroadcastReceiver extends BroadcastReceiver {

	TextView txtInfo;
	
	public  MyBroadcastReceiver(TextView ptxtInfo){
		
		txtInfo=ptxtInfo;
	}
	
	@Override
	public void onReceive(Context context, Intent intent  )  {
		  final String action = intent.getAction();

	        if (action.equals(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED)) {
	            final int state = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF);
	            switch (state) {
	            case NfcAdapter.STATE_OFF:
	            	Log.e("BroadcastReceiver","STATE_OFF");
	            	txtInfo.setText("El adaptador NFC esta apagado");
	            	txtInfo.setTextColor(Color.RED);
	                break;
	            case NfcAdapter.STATE_TURNING_OFF:
	            	Log.e("BroadcastReceiver", "STATE_TURNING_OFF");
	            	txtInfo.setText("Apagando adaptador NFC");
	            	txtInfo.setTextColor(Color.RED);
	                break;
	            case NfcAdapter.STATE_ON:
	            	Log.e("BroadcastReceiver","STATE_ON");
	            	txtInfo.setText("El adaptador NFC esta encendido");
	            	txtInfo.setTextColor(Color.GREEN);
	                break;
	            case NfcAdapter.STATE_TURNING_ON:
	            	Log.e("BroadcastReceiver", "STATE_TURNING_ON");
	            	txtInfo.setText("El adaptador NFC esta encendido");
	            	txtInfo.setTextColor(Color.GREEN);
	                break;
	            }
	        }

	}

}
